package com.ad.pet.app.photo.loader.ui;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.ad.pet.R;
import com.ad.pet.app.photo.loader.BucketAdapter;
import com.ad.pet.app.photo.model.ImageBucket;
import com.ad.pet.common.structure.mvp.BasePresenter;
import com.ad.pet.common.structure.ui.fragment.BaseFragment;

import java.util.List;

/**
 * Created by z on.
 * Des:相册fragment
 * Date: 2017/3/31
 */

public class BucketFragment extends BaseFragment {

    private List<ImageBucket> mDatas;
    private RecyclerView mRecyclerView;
    private BucketAdapter mAdapter;
    private ImageFragment mImageFragment;

    @Override
    protected void initData() {
        mAdapter = new BucketAdapter(mDatas);

    }

    @Override
    protected void initEvents() {
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
//        mRecyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), LinearLayout.VERTICAL));
        mRecyclerView.setAdapter(mAdapter);


        mRecyclerView.addOnItemTouchListener(new OnItemClickListener() {
            @Override
            public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {
                mImageFragment = ImageFragment.newInstance(mDatas.get(position).getImageList());
                PhotoLoaderActivity activity = (PhotoLoaderActivity) getActivity();
                activity.getSupportFragmentManager().beginTransaction()
                        .add(R.id.fl_container, mImageFragment)
                        .show(mImageFragment)
                        .hide(activity.mBucketFragment)
                        .addToBackStack(getClass().getSimpleName())
                        .commit();
            }
        });
    }

    @Override
    protected void initViews() {
        mRecyclerView = findViewById(R.id.recycler_view);


    }

    @Override
    public void initInjector() {

    }

    @Override
    public int initContentView() {
        return R.layout.fragment_list;
    }

    @Override
    protected BasePresenter getPresenter() {
        return null;
    }

    public static BucketFragment newInstance(List<ImageBucket> imageBucketList) {

        Bundle args = new Bundle();
        BucketFragment fragment = new BucketFragment();
        fragment.mDatas = imageBucketList;
        fragment.setArguments(args);
        return fragment;
    }

    public ImageFragment getImageFragment() {
        return mImageFragment;
    }
}
